<?php
namespace backend\controllers;

use backend\base\BaseBackController;
use common\helpers\TFileHelper;
use Yii;
use yii\filters\VerbFilter;

/**
 * Site controller
 */
class CleanController extends BaseBackController
{

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    public function actionIndex(){

        if (Yii::$app->request->isPost){
            $clean = Yii::$app->request->post('clean');
            if (empty($clean)){
                Yii::$app->session->setFlash('error', Yii::t('common', 'please_select_clean_data'));
            }else{
                foreach ($clean as $item){
                    if ($item == 'static'){
                        //静态资源
                        $static_dir = Yii::getAlias('@assets');
                        TFileHelper::removeDir($static_dir, false);
                    }elseif ($item == 'runtime'){
                        //前台缓存
                        Yii::$app->cache->flush();
                        $static_dir = Yii::getAlias('@runtime').'/cache';
                        TFileHelper::removeDir($static_dir, false);
                    }
                }
            }
        }

        return $this->render('index', [

        ]);
    }

}
